package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.News;
import org.hxyjs.entity.Parents;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/newsController")
public class NewsController {
	@Resource
	NewsService newsService;
	@RequestMapping("/getAllNews")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<News> getAllNews() throws Exception {
    	System.out.println("查询全部新闻");
		return newsService.getAllNewss();
    }

	@RequestMapping("/deleteNewsByNno/{nno}")
	@ResponseBody
    public DTO<News> deleteNewsByNno(@PathVariable("nno") String nno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(nno+"删除新闻");
    	return newsService.deleteNewsByNno(nno);
    }

	@RequestMapping("/updateNewsByNno")
	@ResponseBody
	public DTO<News> updateNewsByNno(@RequestBody News news) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改新闻");
		return newsService.updateNewsByNno(news);
	}


	@RequestMapping("/addNews")
	@ResponseBody
	public DTO<News> addNews(@RequestBody News news) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加新闻");
		System.out.println(news);
 		return newsService.addNews(news);
	}

	@RequestMapping("/getNewsByPage")
	@ResponseBody
	public DTO<News> getNewsByPage(PageInfo pageInfo)throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页新闻");
		return newsService.getNewsByPage(pageInfo);
	}

	@RequestMapping("/selectNewsWithCarouselmap/{nno}")
	@ResponseBody
	public DTO<News> selectNewsWithCarouselmap(@PathVariable("nno") String nno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询新闻附上轮播图");
		return newsService.selectNewsWithCarouselmap(nno);
	}
}